﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfControlDemo
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            // 员工列表
            //List<Employee> empList = new List<Employee>()
            //{
            //    new Employee(){Id=1,Name="Tim",Age=30},
            //    new Employee(){Id=2,Name="Tom",Age=26},
            //    new Employee(){Id=3,Name="Guo",Age=26},
            //    new Employee(){Id=4,Name="Yan",Age=25},
            //    new Employee(){Id=5,Name="Owen",Age=30},
            //    new Employee(){Id=6,Name="Victor",Age=30}
            //};
            InitializeComponent();

            //this.listBoxEmployee.DisplayMemberPath = "Name";
            //this.listBoxEmployee.SelectedValuePath = "Id";
            //this.listBoxEmployee.ItemsSource = empList;
        }

        private void buttonVictor_Click(object sender, RoutedEventArgs e)
        {
            Button victorBtn = sender as Button;
            DependencyObject level1 = VisualTreeHelper.GetParent(victorBtn);
            Console.WriteLine(level1.GetType().ToString()); //System.Windows.Controls.ContentPresenter
            DependencyObject level2 = VisualTreeHelper.GetParent(level1);
            Console.WriteLine(level2.GetType().ToString()); //System.Windows.Controls.Border
            DependencyObject level3 = VisualTreeHelper.GetParent(level2);
            Console.WriteLine(level3.GetType().ToString()); //System.Windows.Controls.ListBoxItem
        }
    }

    class Employee
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
    }
}
